package com.unicom.microserv.contest.contest18_web.base;

import com.unicom.microserv.contest.contest18_web.param.Param;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

public abstract class AppController {
    protected Logger log =   LoggerFactory.getLogger(this.getClass());



    @Autowired
    public HtmlContextInfo htmlContextInfo;


    @Autowired
    protected HttpServletRequest request;

    @Autowired
    protected HttpServletResponse response;



    public ModelAndView getindexview(  String packagename,  String controller, String viewname) {
        log.info("===========  view path :"+"/"+packagename+"/"+controller+"/"+viewname);
        if(StringUtils.isEmpty(controller))controller="index";
        if(StringUtils.isEmpty(viewname))viewname="index";
        response.setCharacterEncoding(htmlContextInfo.getCharset());
        ModelAndView modelAndView =new ModelAndView();
        //htmlContextInfo.setBasePath(request.getContextPath());
        htmlContextInfo.setTitle(viewname);
        htmlContextInfo.setPagename(packagename);
        htmlContextInfo.setController(controller);
        htmlContextInfo.setViewname(viewname);
        Param paramdata=new Param();
        Map<String,String[]> params=request.getParameterMap();
        for (String key : params.keySet()) {
            paramdata.put(key,params.get(key)[0]);
        }
        htmlContextInfo.setParams(paramdata);
        modelAndView.setViewName("/"+packagename+"/"+controller+"/"+viewname);
        modelAndView.addObject("webinfo",htmlContextInfo);//通用前台对象
        return modelAndView;
    }
    
   /* public ModelAndView getloginview(  String packagename,  String controller, String viewname) {
        log.info("===========  view path :"+"/"+packagename+"/"+controller+"/"+viewname);
        if(StringUtils.isEmpty(controller))controller="login";
        if(StringUtils.isEmpty(viewname))viewname="index";
        response.setCharacterEncoding(htmlContextInfo.getCharset());
        ModelAndView modelAndView =new ModelAndView();
        htmlContextInfo.setBasePath(request.getContextPath());
        htmlContextInfo.setTitle(viewname);
        htmlContextInfo.setPagename(packagename);
        htmlContextInfo.setController(controller);
        htmlContextInfo.setViewname(viewname);
        Param paramdata=new Param();
        Map<String,String[]> params=request.getParameterMap();
        for (String key : params.keySet()) {
            paramdata.put(key,params.get(key)[0]);
        }
        htmlContextInfo.setParams(paramdata);
        modelAndView.setViewName("/"+packagename+"/"+controller+"/"+viewname);
        modelAndView.addObject("webinfo",htmlContextInfo);//通用前台对象
        return modelAndView;
    }*/

}
